package gaml.java.serializer.primitive;

import gaml.error.GamlException;
import gaml.java.ClassSerializer;
import gaml.yaml.ScalarNode;
import gaml.yaml.YamlNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;
import gaml.yaml.ahchor.YamlAnchorObjectStore;


/**
 * serialize boolean value to yaml
 * parse boolean value from yaml
 * @author shnireck
 *
 */
public class BooleanSerializer implements ClassSerializer <Boolean> {

	@Override
	public YamlNode createNode (YamlNode parent) { return new ScalarNode (parent); }

	@Override
	public Boolean createObject () throws GamlException { return null; }

	@Override
	public Boolean restore (YamlNode node, Boolean object, YamlAnchorCodeStore anchors) throws GamlException { return Boolean.parseBoolean (node.getValue ()); }

	@Override
	public Class <Boolean> getObjectClass () { return Boolean.class; }

	@Override
	public boolean noAnchor () { return true; }

	@Override
	public YamlNode serialize (YamlNode node, Boolean object, YamlAnchorObjectStore anchors) throws GamlException { return node.setValue (object.toString ()); }

}
